//
//  PlanViewController.m
//  MaJangJi
//
//  Created by 嗯，大葱 on 16/9/9.
//  Copyright © 2016年 嗯，大葱. All rights reserved.
//

#import "PlanViewController.h"
#import "FangAn1TableViewCell.h"
#import "FA2TableViewCell.h"
#import "FA3TableViewCell.h"
#import "SDCycleScrollView.h"
#import "FN4TableViewCell.h"
#import "FN5TableViewCell.h"
#import "FN6TableViewCell.h"
#import "PainNextViewController.h"
#define k_Width      [UIScreen mainScreen].bounds.size.width

#define h_Height     [UIScreen mainScreen].bounds.size.height

@interface PlanViewController ()<UITableViewDelegate, UITableViewDataSource,SDCycleScrollViewDelegate>
{
      SDCycleScrollView *cycleScrollView;
     NSString *str;
   BOOL   tempFlag;
    CGFloat tempHieght;
}
@property (nonatomic, strong)UITableView *tablewView;

@end

@implementation PlanViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    tempHieght = 0;
    tempFlag = NO;
    str = @"        的撒娇咖啡馆的撒方便的撒方便的萨空间发表的健身房的部分进口白色的啊方便大家看撒办法靠近办法巴方巴萨的恐怖发生的不放假啊方便的啊方便大使来访啊部分撒的办法大使发表的撒方便的萨办法大撒比饭店撒比发的，四面八方吗，是 v 成本 v 周末";
    [self setBarAndView];//设置bar和视图
    [self configureViewController];
}
#pragma mark 设置视图和导航栏
- (void)setBarAndView {
    self.view.backgroundColor = [UIColor whiteColor];
//    UIView *statusBarView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, k_Width, 20)];
//    statusBarView.backgroundColor=[UIColor colorWithRed:82/255.0 green:82/255.0 blue:82/255.0 alpha:1.0];
//    [self.view addSubview:statusBarView];
}
- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
//返回按钮点击事件
- (void)handleBack {
    [self dismissViewControllerAnimated:YES completion:nil];
}
//视图右侧按钮点击事件
- (void)handleWen {
    
}
#pragma mark配置视图控制器
- (void)configureViewController{
    
    _tablewView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, k_Width, h_Height - 20 - 40) style:(UITableViewStylePlain)];
    _tablewView.delegate = self;
    _tablewView.dataSource = self;
    [self.view addSubview:_tablewView];
    
    UIButton *chooseBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    chooseBtn.frame = CGRectMake(0, h_Height - 40, k_Width, 40);
    [chooseBtn setTitle:@"选择此案例" forState:(UIControlStateNormal)];
    chooseBtn.backgroundColor = [UIColor colorWithRed:255/255.0 green:67/255.0 blue:86/255.0 alpha:1.0];
    [chooseBtn addTarget:self action:@selector(handleTurnViewController) forControlEvents:(UIControlEventTouchUpInside)];
    [self.view addSubview:chooseBtn];
    
    //返回上一界面
    UIButton *backBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    backBtn.frame = CGRectMake(10, 30, 30, 30);
    [backBtn setImage:[UIImage imageNamed:@"返回"] forState:(UIControlStateNormal)];
    [backBtn addTarget:self action:@selector(handleBack) forControlEvents:(UIControlEventTouchUpInside)];
//    backBtn.backgroundColor = [UIColor redColor];
    [self.view addSubview:backBtn];
    
    UIButton *wenBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    wenBtn.frame = CGRectMake(k_Width - 40, 30, 30, 30);
    [wenBtn setImage:[UIImage imageNamed:@"nav_but_help@2x"] forState:(UIControlStateNormal)];
    [wenBtn addTarget:self action:@selector(handleWen) forControlEvents:(UIControlEventTouchUpInside)];
    //    backBtn.backgroundColor = [UIColor redColor];
    [self.view addSubview:wenBtn];
    
    
    
    
    
    [self.tablewView registerNib:[UINib nibWithNibName:@"FangAn1TableViewCell" bundle:nil] forCellReuseIdentifier:@"cell1"];
    
    [self.tablewView registerNib:[UINib nibWithNibName:@"FA2TableViewCell" bundle:nil] forCellReuseIdentifier:@"cell2"];
    
    [self.tablewView registerNib:[UINib nibWithNibName:@"FA3TableViewCell" bundle:nil] forCellReuseIdentifier:@"cell3"];
    
    [self.tablewView registerNib:[UINib nibWithNibName:@"FN4TableViewCell" bundle:nil] forCellReuseIdentifier:@"cell4"];
    
    [self.tablewView registerNib:[UINib nibWithNibName:@"FN5TableViewCell" bundle:nil] forCellReuseIdentifier:@"cell5"];
    [self.tablewView registerClass:[FN6TableViewCell class] forCellReuseIdentifier:@"cell6"];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 5;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0) {
        return 4;
    }
    if (section == 1) {
        return 2;
    }
    if (section == 2) {
        return 5;
    }
    if (section == 3) {
        return 1;
    }
    if (section == 4) {
        return 1;
    }
    else{
           return 0;
    }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            
            FA3TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell3"];
            // 创建不带标题的图片轮播器
            cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0,k_Width,250) delegate:self placeholderImage:[UIImage imageNamed:@"111.png"]];//最后设置占位符
            cycleScrollView.localizationImageNamesGroup = @[@"111.png", @"111.png"]; //本地数组
            //网络数据
            //    cycleScrollView.imageURLStringsGroup = @[@"http://d.hiphotos.baidu.com/zhidao/pic/item/72f082025aafa40f507b2e99aa64034f78f01930.jpg", @"http://b.hiphotos.baidu.com/zhidao/pic/item/4b90f603738da9770889666fb151f8198718e3d4.jpg"];
            cycleScrollView.backgroundColor =[ UIColor clearColor];
            cycleScrollView.bannerImageViewContentMode = UIViewContentModeScaleToFill;
            cycleScrollView.showPageControl = YES;
            self.automaticallyAdjustsScrollViewInsets = NO;
            
            [cell addSubview:cycleScrollView];
            // 轮播时间间隔，默认1.0秒，可自定义
            cycleScrollView.autoScrollTimeInterval = 4.0;
//     cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;
            
        }
        if (indexPath.row == 2) {
            FN6TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell6"];
             cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.txtLabel.text = str;
            
        [cell.tempBtn  addTarget:self action:@selector(handleTenpAction:) forControlEvents:(UIControlEventTouchUpInside)];
            return cell;
        }
        
        if (indexPath.row == 3) {
            FA2TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell2"];
             cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;
        }else {
            FangAn1TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell1"];
             cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.nameLabel.text = @"案例介绍";
            cell.moneyLabel.text = @"顺风棋牌室";
            return cell;
        }
        
    }
    else if (indexPath.section == 2) {
        FangAn1TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell1"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        if (indexPath.row == 0) {
            FN5TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell5"];
             cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;
        }else {
            if (indexPath.row == 1) {
                cell.nameLabel.text = @"麻将桌";
                cell.moneyLabel.text = @"¥111";
            }
            if (indexPath.row == 2) {
                cell.nameLabel.text = @"椅子";
                cell.moneyLabel.text = @"¥222";
            }
            if (indexPath.row == 3) {
                cell.nameLabel.text = @"转盘";
                cell.moneyLabel.text = @"¥333";
            }
            if (indexPath.row == 4) {
                cell.nameLabel.text = @"水晶牌";
                cell.moneyLabel.text = @"¥444";
            }
            
          
            return cell;
        }
        
    }
    
   else if (indexPath.section == 4) {
       FN4TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell4"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
       return cell;
    }
    else {
          FangAn1TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell1"];
         cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        if (indexPath.section == 1) {
            if (indexPath.row == 0) {
                cell.nameLabel.text = @"施工门店";
                cell.moneyLabel.text = @"珺墨网络科技";
            }
            if (indexPath.row == 1) {
                cell.nameLabel.text = @"施工面积";
                cell.moneyLabel.text = @"444平米";
            }
        }
        return cell;
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 10;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            return 250;
        }
        if (indexPath.row == 2) {
            if (tempFlag == YES) {
                return tempHieght+ 30;
            }else {
                return 70;
            }
        }
        else {
            return 40;
        }
    }
    else if(indexPath.section == 4){
        return 80;
    }
    
    else {
        return 40;
    }
}

- (void)handleTenpAction:(UIButton *)sender {
    sender.selected = !sender.selected;
    
  
   FN6TableViewCell  * cell = (FN6TableViewCell *)[[sender superview] superview];
    if (sender.selected == YES) {
        tempFlag = YES;
        ///计算文本高度
        NSDictionary *attribute = @{NSFontAttributeName: [UIFont systemFontOfSize:16]};
        NSStringDrawingOptions option = (NSStringDrawingOptions)(NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading);
        CGSize size = [str boundingRectWithSize:CGSizeMake(k_Width - 30, 100000) options:option attributes:attribute context:nil].size;
        tempHieght = size.height;
        cell.txtLabel.frame = CGRectMake(10, 5, k_Width- 20, size.height);
        cell.txtLabel.numberOfLines = 0;
        cell.tempBtn.frame = CGRectMake(CGRectGetMaxX(cell.txtLabel.frame) - 40, CGRectGetMaxY(cell.txtLabel.frame), 50, 30);
    }
    if (sender.selected == NO) {
         tempFlag = NO;
        cell.txtLabel.numberOfLines = 2;
          cell.txtLabel.frame = CGRectMake(10, 5, k_Width- 20, 40);
       cell.tempBtn.frame = CGRectMake(CGRectGetMaxX(cell.txtLabel.frame) - 40, CGRectGetMaxY(cell.txtLabel.frame), 50, 30);
    }
    
    [self.tablewView reloadData];
    
}



//跳转到下一个界面
- (void)handleTurnViewController {
    PainNextViewController *pl = [[PainNextViewController alloc] init];
    UINavigationController *naV = [[UINavigationController alloc] initWithRootViewController:pl];
    [self presentViewController:naV animated:YES completion:nil];
}

























@end



